home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 13.5 KB | 443 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPoint.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPOINT_H
- #define FWPOINT_H
-
- #ifndef FWFXMATH_H
- #include "FWFxMath.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // Forward Declarations
- //========================================================================================
-
- class FW_CLASS_ATTR ODTransform;
-
- class FW_CLASS_ATTR FW_CRect;
- class FW_CLASS_ATTR FW_CPoint;
- class FW_CLASS_ATTR FW_CWritableStream;
- class FW_CLASS_ATTR FW_CReadableStream;
-
- //========================================================================================
- // Global operators << and >>
- //========================================================================================
-
- FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CPoint& point);
- FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CPoint& point);
-
- //========================================================================================
- // Global
- //========================================================================================
-
- extern const FW_CPoint FW_kZeroPoint;
-
- //========================================================================================
- // Typedefs
- //========================================================================================
-
- typedef unsigned short FW_XYSelector;
-
- const FW_XYSelector FW_kHorizontal = 0;
- const FW_XYSelector FW_kVertical = 1;
-
- //========================================================================================
- // struct FW_SPlatformPoint
- //========================================================================================
-
- struct FW_CLASS_ATTR FW_SPlatformPoint : public FW_PlatformPoint
- {
- FW_SPlatformPoint();
- FW_SPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
- FW_SPlatformPoint(const FW_SPlatformPoint& plfmPoint);
- FW_SPlatformPoint(const FW_PlatformPoint& plfmPoint);
- FW_SPlatformPoint(const FW_CPoint& point);
-
- FW_SPlatformPoint& operator=(const FW_SPlatformPoint& plfmPoint);
- FW_SPlatformPoint& operator=(const FW_PlatformPoint& plfmPoint);
- FW_SPlatformPoint& operator=(const FW_CPoint& point);
-
- void Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
-
- FW_Boolean operator==(const FW_SPlatformPoint& pt) const;
- FW_Boolean operator!=(const FW_SPlatformPoint& pt) const;
-
- FW_PlatformCoordinate X() const;
- FW_PlatformCoordinate Y() const;
-
- FW_PlatformCoordinate& X();
- FW_PlatformCoordinate& Y();
- };
-
- //========================================================================================
- // class FW_CPoint
- // Has the same layout as ODPoint, but the members are FW_CFixed instead of ODFixed,
- // which make the class much easier to use
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CPoint
- {
- //----------------------------------------------------------------------------------------
- // Data members
- //
- public:
- FW_CFixed x, y;
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- public:
- FW_CPoint() : x(FW_IntToFixed(0)), y(FW_IntToFixed(0))
- { }
-
- FW_CPoint(FW_CFixed xx, FW_CFixed yy) : x(xx), y(yy)
- { }
-
- FW_CPoint(FW_PlatformPoint plfmPoint);
- FW_CPoint(const FW_CPoint& point);
- FW_CPoint(const ODPoint& odPoint);
-
- FW_CPoint(const FW_CReadableStream& stream);
-
- //----------------------------------------------------------------------------------------
- // operators
- //
- public:
- // ----- Assignement -----
- FW_CPoint& operator=(const FW_CPoint& point);
- FW_CPoint& operator=(const ODPoint& odPoint);
- FW_CPoint& operator=(FW_PlatformPoint plfmPoint);
-
- // ----- Conversion -----
- // It is too dangerous to have automatic conversion. Use AsPlatformPoint.
- // operator FW_PlatformPoint() const;
- operator ODPoint() const
- { return * (ODPoint*) this; }
-
- // ----- Modification -----
- FW_CPoint& operator+=(const FW_CPoint& point);
- FW_CPoint& operator-=(const FW_CPoint& point);
- FW_CPoint& operator+=(const ODPoint& odPoint);
- FW_CPoint& operator-=(const ODPoint& odPoint);
-
- FW_CPoint operator+(const FW_CPoint& point) const;
- FW_CPoint operator-(const FW_CPoint& point) const;
- FW_CPoint operator+(const ODPoint& odPoint) const;
- FW_CPoint operator-(const ODPoint& odPoint) const;
- FW_CPoint operator-() const;
-
- FW_CPoint& operator+=(FW_SPlatformPoint plfmPoint);
- FW_CPoint& operator-=(FW_SPlatformPoint plfmPoint);
- FW_CPoint operator+(FW_SPlatformPoint plfmPoint) const;
- FW_CPoint operator-(FW_SPlatformPoint plfmPoint) const;
-
- FW_CFixed& operator[](FW_XYSelector selector);
- FW_CFixed operator[](FW_XYSelector selector) const;
-
- // ----- Comparison -----
- FW_Boolean operator==(const FW_CPoint& point) const;
- FW_Boolean operator!=(const FW_CPoint& point) const;
- FW_Boolean operator==(const ODPoint& odPoint) const;
- FW_Boolean operator!=(const ODPoint& odPoint) const;
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Modification -----
- void Clear();
- void Set(FW_CFixed xx, FW_CFixed yy);
- void Offset(FW_CFixed xx, FW_CFixed yy);
- void Map(const FW_CRect& srcRect, const FW_CRect& destRect);
-
- // ----- Conversion -----
- void AsPlatformPoint(FW_PlatformPoint& plfmPoint) const;
-
- // ----- Accessors -----
- short IntX() const;
- short IntY() const;
-
- // ----- OpenDoc transforms -----
- void Transform(Environment* ev, ODTransform* trasnsform);
- void InverseTransform(Environment* ev, ODTransform* transform);
- // Modify the point
-
- FW_CPoint TransformCopy(Environment* ev, ODTransform* trasnsform) const;
- FW_CPoint InverseTransformCopy(Environment* ev, ODTransform* transform) const;
- // Return a transformed copy
-
- // ----- Utilities -----
- static FW_XYSelector GetOrthogonal(FW_XYSelector selector)
- {return (selector + 1) & 1;}
- };
-
- //========================================================================================
- // inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Clear
- //----------------------------------------------------------------------------------------
-
- inline void FW_CPoint::Clear()
- {
- x = y = FW_IntToFixed(0);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Set
- //----------------------------------------------------------------------------------------
- inline void FW_CPoint::Set(FW_CFixed xx, FW_CFixed yy)
- {
- x = xx, y = yy;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::IntX
- //----------------------------------------------------------------------------------------
- inline short FW_CPoint::IntX() const
- {
- return x.AsInt();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::IntY
- //----------------------------------------------------------------------------------------
- inline short FW_CPoint::IntY() const
- {
- return y.AsInt();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::FW_SPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint::FW_SPlatformPoint()
- {
- #ifdef FW_BUILD_WIN
- x = y = 0;
- #endif
- #ifdef FW_BUILD_MAC
- h = v = 0;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::FW_SPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint::FW_SPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
- {
- #ifdef FW_BUILD_WIN
- x = xx; y = yy;
- #endif
- #ifdef FW_BUILD_MAC
- h = xx; v = yy;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::FW_SPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint::FW_SPlatformPoint(const FW_CPoint& point)
- {
- #ifdef FW_BUILD_WIN
- x = point.x.AsInt(), y = point.y.AsInt();
- #endif
- #ifdef FW_BUILD_MAC
- h = point.x.AsInt(), v = point.y.AsInt();
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::FW_SPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint::FW_SPlatformPoint(const FW_SPlatformPoint& plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = plfmPoint.x; y = plfmPoint.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = plfmPoint.h; v = plfmPoint.v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::FW_SPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint::FW_SPlatformPoint(const FW_PlatformPoint& plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = plfmPoint.x; y = plfmPoint.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = plfmPoint.h; v = plfmPoint.v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::operator=
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint& FW_SPlatformPoint::operator=(const FW_CPoint& point)
- {
- #ifdef FW_BUILD_WIN
- x = point.x.AsInt(), y = point.y.AsInt();
- #endif
- #ifdef FW_BUILD_MAC
- h = point.x.AsInt(), v = point.y.AsInt();
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::operator=
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint& FW_SPlatformPoint::operator=(const FW_SPlatformPoint& plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = plfmPoint.x; y = plfmPoint.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = plfmPoint.h; v = plfmPoint.v;
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::operator=
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint& FW_SPlatformPoint::operator=(const FW_PlatformPoint& plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = plfmPoint.x; y = plfmPoint.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = plfmPoint.h; v = plfmPoint.v;
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::Set
- //----------------------------------------------------------------------------------------
- inline void FW_SPlatformPoint::Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
- {
- #ifdef FW_BUILD_WIN
- x = xx; y = yy;
- #endif
- #ifdef FW_BUILD_MAC
- h = xx; v = yy;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::X
- //----------------------------------------------------------------------------------------
- inline FW_PlatformCoordinate FW_SPlatformPoint::X() const
- {
- #ifdef FW_BUILD_WIN
- return x;
- #endif
- #ifdef FW_BUILD_MAC
- return h;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::Y
- //----------------------------------------------------------------------------------------
- inline FW_PlatformCoordinate FW_SPlatformPoint::Y() const
- {
- #ifdef FW_BUILD_WIN
- return y;
- #endif
- #ifdef FW_BUILD_MAC
- return v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::X
- //----------------------------------------------------------------------------------------
- inline FW_PlatformCoordinate& FW_SPlatformPoint::X()
- {
- #ifdef FW_BUILD_WIN
- return x;
- #endif
- #ifdef FW_BUILD_MAC
- return h;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::Y
- //----------------------------------------------------------------------------------------
-
- inline FW_PlatformCoordinate& FW_SPlatformPoint::Y()
- {
- #ifdef FW_BUILD_WIN
- return y;
- #endif
- #ifdef FW_BUILD_MAC
- return v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::operator==
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_SPlatformPoint::operator==(const FW_SPlatformPoint& pt) const
- {
- #ifdef FW_BUILD_WIN
- return x == pt.x && y == pt.y;
- #endif
- #ifdef FW_BUILD_MAC
- return h == pt.h && v == pt.v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformPoint::operator!=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_SPlatformPoint::operator!=(const FW_SPlatformPoint& pt) const
- {
- #ifdef FW_BUILD_WIN
- return x != pt.x || y != pt.y;
- #endif
- #ifdef FW_BUILD_MAC
- return h != pt.h || v != pt.v;
- #endif
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-